package com.zbcx.generate.mbtiles;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.zbcx.generate.mbtiles.db.DBUtils;

public class test {

	public static void main(String[] args) {
				
		
		ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);
		for (int i = 0; i < 2; i++) {
			fixedThreadPool.execute(new Runnable() {
				public void run() {
					try {
						Class.forName(DBUtils.DRIVER_CLASS_NAME);
						Connection conn = DriverManager
								.getConnection(DBUtils.URL);
						Statement stat = conn.createStatement();
						ResultSet rsTables = conn.getMetaData().getTables(null, null, "cx",
								null);
						if (rsTables.next()) {
							System.out.println("表存在,创建表的事情不要做了");
						} else {
							stat.executeUpdate("create table cx(zoom_level INTEGER,tile_row INTEGER,tile_column INTEGER,tile_data BLOB);");
						}
						
						// 关闭事务自动提交
						conn.setAutoCommit(false);

						String sql = "insert into cx(zoom_level, tile_row,tile_column,tile_data) values(?,?,?,?)";
						PreparedStatement ps = null;
						ps = conn.prepareStatement(sql);
						ps.setInt(1, 1);
						ps.setInt(2, 1);
						ps.setInt(3, 1);
						ps.setBytes(4, ImageUtil.getImageByteTest());

						ps.execute();
//						conn.commit();
						
						ps.close();
						conn.close();
						  

					} catch (ClassNotFoundException e) {
						System.out.println("注册失败！");
						e.printStackTrace();
					} catch (Exception e) {
						e.printStackTrace();
					}

				}});
		}
	}
}
